<?php
class Shepherd_InventoryController extends Sss_Controller_Shepherd
{

	private $_menuName = 'Hardware management';

	public function init()
	{
		parent::init();
		$this->checkInstance();
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		if (!$userInformation->username) {
			$this->_redirect("/$handle/user/login");
		}
	}

	public function loginAction()
	{
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$this->_redirect("/$handle/user/login");
	}
	public function indexAction()
	{
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$this->_redirect("/$handle/inventory/stock-location-detail");
	}

	public function stockLocationDetailAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);


		$get  = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::VISIBLE, 'feature', 'action' ,$this->listRole(), true) == 1 ){
			$containerTable     = new Shepherd_Model_Mapper_Container();
			$instanceTable      = new Application_Model_Mapper_Instance();

			//get handle name
			$handle   = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			//get instance
			$instance = $instanceTable->getInstanceByHandle($handle);
			$this->view->assign(Sss_Ultility_CommonViewParamater::INSTANCE, $instance);
			//get order, page, limit param
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
			$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
			$paramSearch = $get[Sss_Ultility_CommonViewParamater::FIX . 'containername'] == Resources::_('NAME') ? '' : $get[Sss_Ultility_CommonViewParamater::FIX . 'containername'];
			$paramName = $isSearch ? $paramSearch : '';

			$filterParam['containername'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'containername', trim($paramName), Sss_Ultility_SessionName::FLOOR_PLAN_SESSION);
			//floor plan
			$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
			$deleteFloorPlanId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ID, -1);
			if ($userInformation->username && isset($deleteFloorPlanId) && $deleteFloorPlanId != -1) {
				$result = Sss_Ultility_InventoryFuction::deleteFloorplan($userInformation->username, $deleteFloorPlanId);
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $result);
			}
			//get floor plan list
			if ($instance) {
				$filterParam['parentid'] = 0;
				$list                 = $containerTable->getContainerList($this->view->limit, 0, $filterParam,null,1);
				$row                  = $list->list;
				$countitems           = array();
				foreach ((array) $row as $r) {
					$roomList     = $containerTable->getRoomsByParentId($r['containerid']);
					$roomList     = $roomList->list;
					$countitems[] = count($roomList);
				}
				$this->view->assign('countitems', $countitems);
				$pagination = $list->pagination;
				$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
				$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
				$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
			}
			//action button
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'stock-location-detail-export?' . "stocklocationid=" . $stockLocationId, Resources::_('PRINT'))
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
			//get breadscrumb
			$breadscrumbs = array(
					new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
					new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
			$orderQueryString = '';
			if ($isSearch) {
				$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE] . '&s=1';
			} else {
				$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
			}
			$queryString = '';
			if ($isSearch) {
				$queryString .= '&s=1';
			}
			if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD])) {
				$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD];
			}
			if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE])) {
				$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE];
			}
			$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
			// check rights for edit stock information
			$lstRoles = $this->listRole();
			$isEdited = false;
			if ($userInformation->username == Sss_Ultility_CommonViewParamater::USER_NAME_SHEPHERD_DEFAULT) {
				$isEdited = true;
			} else {
				foreach ($lstRoles as $role) {
					if ($role['feature'] == 'stock-location' && $role['action'] == 'edit'){
						$isEdited = true;
					}
				}
			}
			$this->view->assign('isEdited', $isEdited);
		} else {
			$this->_redirect("/$handle/shipment/shipments");
		}
	}

	public function stockLocationDetailExportAction()
	{
		$stockLocationTable = new Application_Model_Mapper_StockLocation();
		$containerTable     = new Shepherd_Model_Mapper_Container();
		$params = $this->getRequest()->getPost();
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERFIELD, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERFIELD, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERTYPE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERTYPE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE]       = $this->getValueRequest(Sss_Ultility_CommonViewParamater::PAGE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::PAGE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$page = $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);
		//get stock location by id
		$stockLocation = $stockLocationTable->select($stockLocationId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATION, $stockLocation);

		$queryString = '?stocklocationid=' . $stockLocationId;
		$filterParam['parentid'] = 0;
		$list       = $containerTable->getContainerList(-1, 0, $filterParam,null,1);
		$row        = $list->list;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);

		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_COMMON, Sss_Ultility_CommonViewParamater::ACTION_STOCK_LOCATION_DETAIL);
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		//disable layout
		$this->_helper->layout->disableLayout();
	}

	public function addFloorPlanAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$containerConstructor = new Shepherd_Model_Container();
		$containerTable = new Shepherd_Model_Mapper_Container();
		$stockLocationTable = new Application_Model_Mapper_StockLocation();
		$instanceTable = new Application_Model_Mapper_Instance();
		$params = $this->_request->getParams();

		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);


		$strAction           = Sss_Ultility_CommonViewParamater::ACTION_STOCK_LOCATION_DETAIL;
		$queryString         = "?stocklocationid=" . $stockLocationId;

		$instance = $instanceTable->getInstanceByHandle($handle);
		$stockLocations = $stockLocationTable->getLocationByInstance($instance->instanceid);
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATIONS, $stockLocations);
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);

		//insert stock location
		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			if ($userInformation->username) {
				$createBy   = $userInformation->accountid;
				$createDate = Sss_Ultility_Common::getDateTimeNumber();
				// Upload new file
				$photo = @array_shift(Sss_Ultility_Common::uploadFiles(
						@$_FILES['file_upload'],
						array(
								'fullPath'    => Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER,
								'fullUrl'     => '/'.Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER
						)
				));
				$data = array();
				$data['photo'] = empty($photo)?'':$photo['fullUrl'];

				// Upload new file
				$photoFloorplan = @array_shift(Sss_Ultility_Common::uploadFiles(
						@$_FILES['file_upload2'],
						array(
								'fullPath'    => Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER,
								'fullUrl'     => '/'.Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER
						)
				));
				$data['photofloorplan'] = empty($photoFloorplan)?'':$photoFloorplan['fullUrl'];
				$data['width'] = empty($photoFloorplan)?0:$photoFloorplan['width'];
				$data['height'] = empty($photoFloorplan)?0:$photoFloorplan['height'];

				$containerConstructor->setContainerName($params['containername']);
				$containerConstructor->setCreatedBy($createBy);
				$containerConstructor->setCreatedDate($createdDate);
				$containerConstructor->setStockLocation(trim($params['stocklocation']));
				$containerConstructor->setUpdatedBy($createBy);
				$containerConstructor->setCreatedDate($createdDate);
				$containerConstructor->setUpdatedDate($createDate);
				$containerConstructor->setParentId(0);
				$containerConstructor->setIsused(1);
				$containerConstructor->setPhoto($data['photo']);
				$containerConstructor->setPhotoFloorplan($data['photofloorplan']);
				$containerConstructor->setWidth($data['width']);
				$containerConstructor->setHeight($data['height']);

				// Process adding new stock location
				$countainerId = $containerTable->save($containerConstructor, $instanceId);
				if (isset($countainerId)) {
					$this->redirect(Resources::_('ADD_FLOOR_PLAN_SUCCESSFULL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $strAction
					)));
				} else {
					$this->redirect(Resources::_('ADD_FLOOR_PLAN_FAIL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $strAction
					)));
				}
			}
		}
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_FLOOR_PLAN'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function editFloorPlanAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::EDIT, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
			
		$containerTable = new Shepherd_Model_Mapper_Container();
		$stockLocationTable = new Application_Model_Mapper_StockLocation();
		$instanceTable = new Application_Model_Mapper_Instance();
		$params = $this->getRequest()->getPost();

		$instance = $instanceTable->getInstanceByHandle($handle);
		$stockLocations = $stockLocationTable->getLocationByInstance($instance->instanceid);
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATIONS, $stockLocations);

		$stockLocationId = $this->getRequest()->getParam('stocklocation', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocation']))
			$stockLocationId = $params['stocklocation'];

		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['containerid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);


		$strAction           = Sss_Ultility_CommonViewParamater::ACTION_STOCK_LOCATION_DETAIL;
		$queryString         = '';

		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);

		//get stock location by id
		$container = $containerTable->getContainer($containerId);
		if($stockLocationId == -1) {
			$stockLocationId  = $container->stocklocation;
		}
		$this->view->assign('stocklocation', $stockLocationId);
		$deleteImage = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_IMAGE_ID, -1);
		$phototype = $this->getRequest()->getParam('phototype');
			
		if (isset($deleteImage) && $deleteImage != -1 && !empty($phototype) ) {
			$container = $containerTable->getContainer((int) $deleteImage);
			$containerDelete = $containerTable->findById($params['containerid']);
			switch ($phototype) {
				case 'plan' :
					( !is_file(getcwd() . $container->{'photo'}) )
					or unlink(getcwd() . $container->{'photo'});
					$arrData['photo'] = null;
					$containerDelete->setPhoto("");
					break;
				case 'photo' :
					( !is_file(getcwd() . $container->{'photofloorplan'}) )
					or unlink(getcwd() . $container->{'photofloorplan'});
					$arrData['photofloorplan'] = null;
					$containerDelete->setPhotoFloorplan("");
					break;
			}
			$updateId = $containerTable->save($containerDelete, $instanceId);
			if (isset($updateId)) {
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_FLOOR_PLAN_IMAGE_SUCCESSFULL'));
			} else {
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_FLOOR_PLAN_IMAGE_FAIL'));
			}
		}

		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE]) && $containerId != -1) {
			$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
			if ($userInformation->username) {
				$updateBy = $userInformation->accountid;
				$result = Sss_Ultility_InventoryFuction::editFloorplan($params, $updateBy, $container, $_FILES['file_upload'], $_FILES['file_upload2'], $containerId,$instanceId);
				$this->redirect($result, $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $strAction
				)) . $queryString);
			}
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::CONTAINER, $containerTable->getContainer($containerId));

		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('EDIT_FLOOR_PLAN'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function roomAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		$get  = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		$containerTable = new Shepherd_Model_Mapper_Container();
		$allocationTable = new Shepherd_Model_Mapper_Allocation();
		$params = $this->getRequest()->getPost();
		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);

		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['stocklocationid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);
		$strAction = Sss_Ultility_CommonViewParamater::ACTION_STOCK_LOCATION_DETAIL;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramName = $isSearch ? strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'containername', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('NAME')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'containername', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		$filterParam['containername'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'containername', trim($paramName), Sss_Ultility_SessionName::ROOM_SESSION);
		//room
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		if ($userInformation->username) {
			$deleteRoomId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ID, -1);
			$hardwareByRoom = $allocationTable->getById($deleteRoomId, Sss_Ultility_SystemName::ROOMS);
			if(count($hardwareByRoom) > 0 && $hardwareByRoom != false && isset($deleteRoomId) && $deleteRoomId != -1) {
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_ROOM_FAIL').'. '.Resources::_('ROOM_EXIST_HARDWARE'));
			} else {
				if (isset($deleteRoomId) && $deleteRoomId != -1) {
					$container = $containerTable->getContainer($deleteRoomId);
					if ($container && $container->photo)
						if (file_exists(getcwd() . $container->photo))
						unlink(getcwd() . $container->photo);
					$result = Sss_Ultility_InventoryFuction::deleteRoom($deleteRoomId,$instanceId);
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $result);
				}
			}
		}
		//get floor plan list
		$filterParam['parentid'] = $containerId;
		$list                                             = $containerTable->getContainerList($this->view->limit, 0, $filterParam);
		$row                                              = $list->list;
		$pagination                                       = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$queryString = '&' . 'containerid' . "=" . $containerId;
		$orderQueryString = '&' . 'containerid' . "=" . $containerId;

		if ($isSearch) {
			$orderQueryString .= '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE] . '&s=1';
		} else {
			$orderQueryString .= '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD];
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE];
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'stock-location-detail', Resources::_('BTN_BACK')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'room-export?containerid=' . $containerId . '&export=1', Resources::_('EXPORT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'room-export?containerid=' . $containerId . '&print=1', Resources::_('PRINT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
		);
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) == 1 || $userInformation->username == Sss_Ultility_CommonViewParamater::USER_NAME_SHEPHERD_DEFAULT) {
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'stock-location-detail', Resources::_('BTN_BACK')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADD, 'add-room?containerid=' . $containerId, Resources::_('ADD_NEW_ROOM')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'room-export?containerid=' . $containerId . '&export=1', Resources::_('EXPORT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'room-export?containerid=' . $containerId . '&print=1', Resources::_('PRINT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ROOM'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function roomExportAction()
	{
		$containerTable = new Shepherd_Model_Mapper_Container();
		$params = $this->getRequest()->getPost();

		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);

		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['stocklocationid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);


		$queryFloorPlanString = '?' . 'stocklocationid' . "=" . $stockLocationId;


		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramName = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'containername', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('NAME')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'containername', Sss_Ultility_CommonViewParamater::UNDERFINE);



		$filterParam['containername'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'containername', $paramName, Sss_Ultility_SessionName::CONTAINER_SESSION);



		//get floor plan list
		$filterParam['parentid'] = $containerId;
		$list                                             = $containerTable->getContainerList(-1, 0, $filterParam);
		$rowAll                                              = $list->list;
		$pagination                                       = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);

		$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));
		$columnNames = array(
				Resources::_('ID'),
				Resources::_('NAME'),
				Resources::_("Shape (Ex: rect or circle or poly)") ,
				Resources::_('Coords (Ex: 0,42,82,126 or 90,58,3 or 10,0,14,3,7,10)')
		);

		$arrData = array();
		$index = 0;
		foreach((array)$rowAll as $row)
		{
			$count++;
			$arrData[$index][] = $count;
			$arrData[$index][] = $row['containername'];
			$arrData[$index][] = $row['top_value'];
			$arrData[$index][] = $row['left_value'];
			$index++;
		}
		if(isset($_GET['export']))
			$this->exportDataToExcel($columnNames, $arrData, Resources::_('ROOM'));
	}

	public function addRoomAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$containerTable = new Shepherd_Model_Mapper_Container();
		$instanceTable  = new Application_Model_Mapper_Instance();
		$params = $this->_request->getParams();

		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);
		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['stocklocationid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);

		$strAction            = 'room';

		$queryString          = '?' . 'containerid' . "=" . $containerId;
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);
		//insert stock location
		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			$instance = $instanceTable->getInstanceByHandle($handle);
			$addRoomConstructor = new Shepherd_Model_Container();
			$containerTable->checkEsixtedColumns('compressor', $instance->instanceid);
			$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
			if ($userInformation->username) {
				$createBy   = $userInformation->accountid;
				$createDate = strtotime(date(DATETIME_MYSQL_FORMAT));
				$addRoomConstructor->setContainerName($params['containername']);
				$addRoomConstructor->setTopValue($params['top_value']);
				$addRoomConstructor->setLeftValue($params['left_value']);
				$addRoomConstructor->setCreatedBy($createBy);
				$addRoomConstructor->setUpdatedBy($createBy);
				$addRoomConstructor->setCreatedDate($createDate);
				$addRoomConstructor->setUpdatedDate($createDate);
				$addRoomConstructor->setParentId($containerId);
				$addRoomConstructor->setCompressorType($params['compressor_type']);
				$addRoomConstructor->setLastestRevision($params['lastest_revision']);
				$addRoomConstructor->setRoomValue($params['room_value']);
				$addRoomConstructor->setIsolationMaterial($params['isolation_material']);
				$addRoomConstructor->setIsused(1);
				$addRoomConstructor->setCompressor($params['compressor']);
				// Upload new file
				$data = array();
				$photo = @array_shift(Sss_Ultility_Common::uploadFiles(
						@$_FILES['file_upload'],
						array(
								'fullPath'    => Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER,
								'fullUrl'     => '/'.Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER
						)
				));
				$data['photo'] = empty($photo)?'':$photo['fullUrl'];
				$data['width'] = empty($photo)?0:$photo['width'];
				$data['height'] = empty($photo)?0:$photo['height'];
				// Upload new file
				$photoFloorplan = @array_shift(Sss_Ultility_Common::uploadFiles(
						@$_FILES['file_upload2'],
						array(
								'fullPath'    => Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER,
								'fullUrl'     => '/'.Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_CONTAINER
						)
				));
				$data['photofloorplan'] = empty($photoFloorplan)?'':$photoFloorplan['fullUrl'];
				$addRoomConstructor->setPhoto($data['photo']);
				$addRoomConstructor->setPhotoFloorplan($data['photofloorplan']);
				$addRoomConstructor->setWidth($data['width']);
				$addRoomConstructor->setHeight($data['height']);
				// Process adding new stock location
				$countainerId = $containerTable->save($addRoomConstructor, $instanceId);
				if (isset($countainerId)) {
					$message = Resources::_('ADD_ROOM_SUCCESSFULL');
				} else {
					$message = Resources::_('ADD_ROOM_FAIL');
				}
				$this->redirect( $message , $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $strAction
				)) . $queryString);
			}
		}
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ROOM'), $strAction . $queryString),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_ROOM'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function editRoomAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		$historyTable = new Shepherd_Model_Mapper_History();

		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::EDIT, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$containerTable = new Shepherd_Model_Mapper_Container();
		$instanceTable  = new Application_Model_Mapper_Instance();
		$params = $this->getRequest()->getPost();

		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);

		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['containerid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);

		$roomId = $this->getRequest()->getParam('roomid', -1);
		if (($roomId == -1 || (int) $roomId == 0) && isset($params['roomid']))
			$roomId = $params['roomid'];
		$this->view->assign('roomid', $roomId);

		//get history list
		$history = $historyTable->getList(Sss_Ultility_Setting::HISTORY_TYPE_ROOM , $roomId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORY, $history);

		$reFloorPlan = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::RE_FLOORPLAN, -1);
		if (($reFloorPlan == -1 || (int) $reFloorPlan == 0) && isset($params[Sss_Ultility_CommonViewParamater::RE_FLOORPLAN]))
			$reFloorPlan = $params[Sss_Ultility_CommonViewParamater::RE_FLOORPLAN];
		$this->view->assign(Sss_Ultility_CommonViewParamater::RE_FLOORPLAN, $reFloorPlan);

		$strAction            = 'room';
		$strControllerName    = 'inventory';
		$queryString          = '?' . 'containerid' . "=" . $containerId;

		if ($reFloorPlan != -1) {
			$strAction         = '';
			$strControllerName = '';
			$queryString       = '?' . 'floorplan' . '=' . $containerId . '&' . 'room' . '=' . $roomId . '&' . Sss_Ultility_CommonViewParamater::RE_FLOORPLAN . '=' . $reFloorPlan;
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);
		$this->view->assign(Sss_Ultility_CommonViewParamater::CONTROLLER, $strControllerName);

		//get stock location by id
		$container = $containerTable->getContainer($roomId, null, null, 1);

		$deleteImage = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_IMAGE_ID, -1);
		$phototype = $this->getRequest()->getParam('phototype');

		if (isset($deleteImage) && $deleteImage != -1 && !empty($phototype) ) {
			$container = $containerTable->getContainer((int) $deleteImage);
			$result = Sss_Ultility_InventoryFuction::deleteImage($phototype, $container, $deleteImage, $instanceId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $result);

		}

		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE]) && $roomId != -1) {
			$instance = $instanceTable->getInstanceByHandle($handle);
			$containerTable->checkEsixtedColumns('compressor', $instance->instanceid);
			if ($userInformation->username) {
				$updateBy   = $userInformation->accountid;
				$updateDate = Sss_Ultility_Common::getDateTimeNumber();
				$result = Sss_Ultility_InventoryFuction::editRoom($params, $roomId, $updateBy, $updateDate, $container, $_FILES['file_upload'], $_FILES['file_upload2'], $userInformation->username, $instanceId);
				$this->redirect($result, $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $strControllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $strAction
				)) . $queryString);
			}
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::CONTAINER,$containerTable->getContainer($roomId, null, null, 1));
		$this->view->assign('roomstatistic', $this->getRoomStatisticInformation($roomId));
		//get breadscrumb
		$strAction    = 'room';
		$queryString  = '?' . 'containerid' . "=" . $containerId;

		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ROOM'), $strAction . $queryString),
				new Sss_CommonEntity_BreadScrumb(Resources::_('EDIT_ROOM'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function roomHardwareAction()
	{
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		$get  = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$allocationTable = new Shepherd_Model_Mapper_Allocation();
		$params = $this->getRequest()->getPost();

		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['containerid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);

		$roomId = $this->getRequest()->getParam('roomid', -1);
		if (($roomId == -1 || (int) $roomId == 0) && isset($params['roomid']))
			$roomId = $params['roomid'];
		$this->view->assign('roomid', $roomId);

		$strAction       = 'room';
		$queryRoomString = '?' . 'containerid' . "=" . $containerId;
		$queryString     = '&' . 'containerid' . "=" . $containerId . "&" . 'roomid' . "=" . $roomId;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramHardwareId     = $isSearch ? strcmp($this->getRequest()->getParam('hardwareid', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ID')) == 0 ? '' : $this->getRequest()->getParam('hardwareid', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramHardwareName   = $isSearch ? strcmp($this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('HARDWARE_NAME')) == 0 ? '' : $this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramHardwareSerial = $isSearch ? strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramHardwareVendor = $isSearch ? strcmp($this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR')) == 0 ? '' : $this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		//get harware filter
		$filterParam['hardwareid']   = $this->getValueRequest('hardwareid', trim($paramHardwareId), Sss_Ultility_SessionName::ROOM_HARDWARE_SHEPHERD_SESSION);
		$filterParam['hardwarename'] = $this->getValueRequest('hardwarename', trim($paramHardwareName), Sss_Ultility_SessionName::ROOM_HARDWARE_SHEPHERD_SESSION);
		$filterParam['serial_number'] = $this->getValueRequest('serial_number', trim($paramHardwareSerial), Sss_Ultility_SessionName::ROOM_HARDWARE_SHEPHERD_SESSION);
		$filterParam['vendorname']        = $this->getValueRequest('vendorname', trim($paramHardwareVendor), Sss_Ultility_SessionName::ROOM_HARDWARE_SHEPHERD_SESSION);

		//get harware filter
		$filterParam['destination'] = $roomId;
		$filterParam['systemname']  = Sss_Ultility_SystemName::ROOMS;
		if ($userInformation->username) {
			$deleteAllocationId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ID, -1);
			if (isset($deleteAllocationId) && $deleteAllocationId != -1) {
				$deleteId        = $allocationTable->deleteRow($deleteAllocationId,$instanceId);
				$message = isset($deleteId) ? Resources::_('REMOVE_SENSOR_SUCCESSFULL') : Resources::_('REMOVE_SENSOR_FAIL');
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $message);
			}
		}
		//get hardware list
		$list = $allocationTable->getList($this->view->limit, 0, $filterParam);
		$row  = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$orderQueryString = '&' . 'containerid' . "=" . $containerId . "&" . 'roomid' . "=" . $roomId;
		$orderQueryString .= ($isSearch) ? '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE] . '&s=1' : '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		$queryString .= !is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] : $queryString;
		$queryString .= !is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] : $queryString;

		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, "room?containerid=$containerId", Resources::_('BTN_BACK')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
		);
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) == 1 || $userInformation->username == Sss_Ultility_CommonViewParamater::USER_NAME_SHEPHERD_DEFAULT) {
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, "room?containerid=$containerId", Resources::_('BTN_BACK')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADD, 'room-add-hardware?containerid=' . $containerId . '&roomid=' . $roomId, Resources::_('ATTACH_HARDWARE_ROOM')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);

		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ROOM'), $strAction . $queryRoomString),
				new Sss_CommonEntity_BreadScrumb(Resources::_('LIST_HARDWARE_IN_ROOM'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function roomAddHardwareAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$get  = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		$hardwareTable = new Application_Model_Mapper_Hardware();

		$containerTable = new Shepherd_Model_Mapper_Container();

		$stockLocationInstanceTable = new Application_Model_Mapper_StockLocationInstance();
		$instanceTable  = new Application_Model_Mapper_Instance();
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramHardwareName   = $isSearch ? strcmp($this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('HARDWARE_NAME')) == 0 ? '' : $this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramHardwareSerial = $isSearch ? strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramHardwareVendor = $isSearch ? strcmp($this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR')) == 0 ? '' : $this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		//get harware filter
		$filterParam['hardwarename'] = $this->getValueRequest('hardwarename', trim($paramHardwareName), Sss_Ultility_SessionName::SHIPMENT_HARDWARE_SESSION);
		$filterParam['serial_number'] = $this->getValueRequest('serial_number', trim($paramHardwareSerial), Sss_Ultility_SessionName::SHIPMENT_HARDWARE_SESSION);
		$filterParam['vendor']        = $this->getValueRequest('vendor', trim($paramHardwareVendor), Sss_Ultility_SessionName::SHIPMENT_HARDWARE_SESSION);
		$defaultNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::SHEPHERD_SYSTEM . $this->getCurrentHandle());
		$filterParam['stocklocation'] = $defaultNamespace->stocklocationId;
		//get shipmentid
		$params          = $this->getRequest()->getPost();
		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);
		$instance = $instanceTable->getInstanceByHandle($handle);
		$stockLocations = $instance?$stockLocationInstanceTable->getStockLocationByInstance($instance->instanceid):null;
		$stockLocationIds = '';
		if($stockLocations != null && count($stockLocations) > 0) {
			foreach($stockLocations as $s){
				$stockLocationIds = $stockLocationIds == ''?$s['stocklocation']:$stockLocationIds.','.$s['stocklocation'];
			}
		}
		if($stockLocationIds != '') {
			$filterParam['stocklocation'] = $stockLocationIds;
		}
		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['containerid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);
		$roomId = $this->getRequest()->getParam('roomid', -1);
		$getDataContainer = $containerTable->getContainer($roomId);
		if (($roomId == -1 || (int) $roomId == 0) && isset($params['roomid']))
			$roomId = $params['roomid'];
		$this->view->assign('roomid', $roomId);
		//get query string
		$strAction            = 'room-hardware';
		$queryRoomString      = 'containerid' . "=" . $containerId;
		$queryString          = $queryRoomString . "&roomid=" . $roomId;
		if ($params && $userInformation->username && !$isSearch) {
			//assign hardware to item
			$arrAssignHardwareId = explode('_', $params[Sss_Ultility_CommonViewParamater::IDS]);
			$errorMsg = '';
			if (false != $arrAssignHardwareId) {
				$errorMsg = Sss_Ultility_InventoryFuction::assignHardwareInRoom($params,$arrAssignHardwareId,$roomId, $getDataContainer, $instanceId);
				$this->redirect($errorMsg, $this->view->url(array(Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName, Sss_Ultility_CommonViewParamater::ACTION => 'room-hardware'))."?".$queryString);
			}
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);

		$list       = $hardwareTable->getListForItem($this->view->limit, 0, $filterParam);
		$row        = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign('isSearch', $isSearch);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
		);
		$actionbuttons = count($row) <= 0? null : $actionbuttons;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ROOM'), 'room' . "?" . $queryRoomString),
				new Sss_CommonEntity_BreadScrumb(Resources::_('LIST_HARDWARE_IN_ROOM'), $strAction . "?" . $queryString),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ATTACH_HARDWARE_ROOM'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function roomHardwareEditAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle          = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::EDIT, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$allocationTable = new Shepherd_Model_Mapper_Allocation();
		$params = $this->getRequest()->getPost();

		$containerId = $this->getRequest()->getParam('containerid', -1);
		if (($containerId == -1 || (int) $containerId == 0) && isset($params['containerid']))
			$containerId = $params['containerid'];
		$this->view->assign('containerid', $containerId);

		$roomId = $this->getRequest()->getParam('roomid', -1);
		if (($roomId == -1 || (int) $roomId == 0) && isset($params['roomid']))
			$roomId = $params['roomid'];
		$this->view->assign('roomid', $roomId);

		$allocationId = $this->getRequest()->getParam('allocationid', -1);
		if (($allocationId == -1 || (int) $allocationId == 0) && isset($params['allocationid']))
			$allocationId = $params['allocationid'];
		$this->view->assign('allocationid', $allocationId);

		$strAction   = 'room-hardware';
		$queryString = '?' . 'containerid' . "=" . $containerId . "&" . 'roomid' . "=" . $roomId;
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);

		$allocation = $allocationTable->getAllocationById($allocationId);
		$layerid      = $this->getRequest()->getParam('layer', -1);
		$graphvalueid = $this->getRequest()->getParam('valuetype', -1);
		//get value edit not request
		if ($allocationId) {
			$layerid = $layerid == -1 ? $allocation->layer : $layerid;
			$graphvalueid = $graphvalueid == -1 ? $allocation->valuetype : $graphvalueid;
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $allocation);
		$this->view->assign('layer', $layerid);
		$this->view->assign('valuetype', $graphvalueid);
		// Start add field layers and field defaule gragh value
		$systemtypeTable       = new Application_Model_Mapper_SystemType();
		$hardwareTable         = new Application_Model_Mapper_Hardware();
		$sensorid     = $this->getRequest()->getParam('hardware', -1);
		//get dropdownlist layer
		$layers = $systemtypeTable->getSystemBySystemName(Sss_Ultility_SystemName::LAYERS);
		//get dropdownlist graph value
		$graphValue = null;
		$graphValue = $sensorid != -1 ? $hardwareTable->getHardwareValueTypeList($sensorid) : null;

		$this->view->assign(Sss_Ultility_CommonViewParamater::LAYERS, $layers);
		$this->view->assign(Sss_Ultility_CommonViewParamater::GRAPH_VALUE, $graphValue);
		//End add field
		//Start Add field Sensor icon
		$fullPath = null;
		$fileName = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::NAME];
		if ($fileName) {
			if($allocation->sensor_icon) {
				if(file_exists(getcwd().$allocation->sensor_icon))
					unlink(getcwd().$allocation->sensor_icon);
			}
			$filePath = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::TMP_NAME];
			$newPath  = Sss_Ultility_CommonViewParamater::FILE_PATH . $fileName;
			move_uploaded_file($filePath, $newPath);
			$fullPath     = '/' . Sss_Ultility_CommonViewParamater::FILE_PATH . $fileName;
		}
		// Edit allocation
		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE]) && $allocationId != -1) {
			if ($userInformation->username) {
				$result = Sss_Ultility_InventoryFuction::editHardwareInRoom($params, $fileName, $allocationId, $fullPath);
				$this->redirect($result, $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $strAction
				)) . $queryString);
			}
		}
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VIEW_STOCK_LOCATION'), 'stock-location-detail'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ROOM'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('LIST_HARDWARE_IN_ROOM'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('BTN_EDIT'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function shipmentStockLocationSearchAction()
	{
		$stocklocationsTable = Sss_Service_Locator::getInstance()->getService($this->_getOvisTable('StockLocation'));

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERFIELD, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERFIELD, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERTYPE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERTYPE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE]       = $this->getValueRequest(Sss_Ultility_CommonViewParamater::PAGE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::PAGE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		//test param filter: omit title text in field
		$paramName    = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_NAME')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramContact = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_CONTACT')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramType    = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_TYPE')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE);


		$page = $filterParam[Sss_Ultility_CommonViewParamater::PAGE];

		$filterParam['stocklocationname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', $paramName, Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam['contact']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'contact', $paramContact, Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam['stocklocationtype'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', $paramType, Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);


		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);


		//$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		//get Stock locations list
		$list       = $stocklocationsTable->getList($limit, 0, $filterParam);
		$row        = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LIMIT, $limit);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
	}
	public function popupStockLocationAction()
	{
		$stocklocationsTable = Sss_Service_Locator::getInstance()->getService($this->_getOvisTable('StockLocation'));

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERFIELD, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERFIELD, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERTYPE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERTYPE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE]       = $this->getValueRequest(Sss_Ultility_CommonViewParamater::PAGE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::PAGE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		//test param filter: omit title text in field
		$paramName    = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_NAME')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramContact = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_CONTACT')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramType    = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_TYPE')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE);



		$filterParam['stocklocationname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', $paramName, Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam['contact']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'contact', $paramContact, Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam['stocklocationtype'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', $paramType, Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		$rma = $this->getRequest()->getParam('rma', -1);
		if($rma != -1){
			$filterParam['typeid'] = Sss_Ultility_Setting::INTERNAL_STOCK;
		}

		//get Stock locations list
		$list       = $stocklocationsTable->getList($limit, 0, $filterParam);
		$row        = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LIMIT, $limit);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
	}
	public function rmaAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		$get  = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_RMA, Sss_Ultility_CommonViewParamater::ALL, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/shipment/shipments");
		}
		$shipmentTable = new Shepherd_Model_Mapper_Shipment();

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramOriginal        =  $isSearch ? $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'origin', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramDestination     = $isSearch ? $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'destination', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramFromDate     = $isSearch ? strcmp($this->getRequest()->getParam('date_from', Sss_Ultility_CommonViewParamater::UNDERFINE), '') == 0 ? '' : $this->getRequest()->getParam('date_from', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramToDate       = $isSearch ? strcmp($this->getRequest()->getParam('date_to', Sss_Ultility_CommonViewParamater::UNDERFINE), '') == 0 ? '' : $this->getRequest()->getParam('date_to', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramInternalRef     = $isSearch? $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramSupplierRef     = $isSearch ? $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramReferenceNumber = $isSearch ? $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		//get shipment filter
		$filterParam['origin']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'origin', trim($paramOriginal), 'shipmentSession');
		$filterParam['destination']      = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'destination', trim($paramDestination), 'shipmentSession');
		$filterParam['date_from']        = $this->getValueRequest('date_from', $paramFromDate, 'shipmentSession');
		$filterParam['date_to']          = $this->getValueRequest('date_to', $paramToDate, 'shipmentSession');
		$filterParam['internal_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', trim($paramInternalRef), 'shipmentSession');
		$filterParam['supplier_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', $paramSupplierRef, 'shipmentSession');
		$filterParam['reference_number'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', trim($paramReferenceNumber), 'shipmentSession');
		$shipmentId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ID, -1);
		if ($userInformation->username && isset($shipmentId) && $shipmentId != -1) {
			$result = Sss_Ultility_InventoryFuction::deleteShipment($shipmentId, $instanceId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $result);
		}
		$params     = $this->getRequest()->getPost();
		//update hardware when detach
		if($userInformation->username && isset($params['hardwareid']) && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			$result = Sss_Ultility_InventoryFuction::detachHardware($params,NULL,NULL, $instanceId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $result);
		}
		$filterParam['shipment_history'] = 0;
		$filterParam['shipmenttype'] = Sss_Ultility_Setting::RMA;
		//get shipment list
		$list                 = $shipmentTable->getList($this->view->limit, 0, $filterParam);
		$row                  = $list->list;
		$result = Sss_Ultility_InventoryFuction::rmaProccess($row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::AUTOCOMPLETE, $result[Sss_Ultility_CommonViewParamater::AUTOCOMPLETE]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE_BY_SHIPMENT, $result[Sss_Ultility_CommonViewParamater::HARDWARE_BY_SHIPMENT]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM_COUNT, $result[Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM_COUNT]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT, $result[Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM, $result[Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM, $result[Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM, $result[Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM]);
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$arrQueryString = Sss_Ultility_AdministrationFunction::getQueyString($isSearch, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $arrQueryString['querystring']);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $arrQueryString['oquerystring']);
		//action button
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_QUERY_STRING, '?' . 'status' . "=" . Sss_Ultility_Setting::RMA);
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_CONTROLLER_NAME, Sss_Ultility_CommonViewParamater::INVENTORY);
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADDOTHER, 'add-shipment', Resources::_('ADD_NEW_RMA_SHIPMENT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'rma-export?export=1', Resources::_('EXPORT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'rma-export?print=1', Resources::_('PRINT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH')));
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'shipment-export?export=1', Resources::_('EXPORT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'shipment-export?print=1', Resources::_('PRINT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('RMA'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function rmaExportAction()
	{
		$shipmentTable = new Shepherd_Model_Mapper_Shipment();


		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramOriginal        = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'origin', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramDestination     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'destination', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramFromDate        = $this->getRequest()->getParam('date_from', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramToDate          = $this->getRequest()->getParam('date_to', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramInternalRef     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramSupplierRef     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramReferenceNumber = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', Sss_Ultility_CommonViewParamater::UNDERFINE);



		//get shipment filter
		$filterParam['origin']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'origin', trim($paramOriginal), 'shipmentSession');
		$filterParam['destination']      = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'destination', trim($paramDestination), 'shipmentSession');
		$filterParam['date_from']        = $this->getValueRequest('date_from', $paramFromDate, 'shipmentSession');
		$filterParam['date_to']          = $this->getValueRequest('date_to', $paramToDate, 'shipmentSession');
		$filterParam['internal_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', trim($paramInternalRef), 'shipmentSession');
		$filterParam['supplier_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', $paramSupplierRef, 'shipmentSession');
		$filterParam['reference_number'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', $paramReferenceNumber, 'shipmentSession');



		//get shipment history
		$shipmentHistoryId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::SHIPMENT_HISTORY, -1);

		$columnNames = array(
				Resources::_('ID'),
				Resources::_('NAME'),
				Resources::_('SHIPMENT_ORGIN_LIST'),
				Resources::_('SHIPMENT_DESTINATION_LIST'),
				Resources::_('DATE')
		);
		$filterParam['shipment_history'] = 0;
		$filterParam['shipmenttype'] = Sss_Ultility_Setting::RMA;

		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_HISTORY, $shipmentHistoryId);
		//get shipment list
		$list = $shipmentTable->getList(-1, 0, $filterParam);
		$rowAll  = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));
		$arrData = array();
		$index = 0;
		foreach((array)$rowAll as $row)
		{
			$count++;
			$arrData[$index][] = $count;
			$arrData[$index][] = $row['shipmentname'];
			$arrData[$index][] = $row['origin'];
			$arrData[$index][] = $row['destination'];
			$arrData[$index][] = Sss_Ultility_Common::getDateTime(DATETIMEFORMAT, $row['ship_date']);
			$index++;
		}

		if(isset($_GET['export']))
			$this->exportDataToExcel($columnNames, $arrData, Resources::_('RMA'));
	}
	public function rmaDetailAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_RMA, Sss_Ultility_CommonViewParamater::ALL, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$systemTypeTable = new Shepherd_Model_Mapper_SystemType();
		$shipmentTable   = new Shepherd_Model_Mapper_Shipment();
		$alertTable      = new Shepherd_Model_Mapper_Alert();
		$productTable    = new Shepherd_Model_Mapper_Product();
		$documentTable   = new Shepherd_Model_Mapper_Document();
		$hardwareTable   = new Application_Model_Mapper_Hardware();
		$allocationTable = new Shepherd_Model_Mapper_Allocation();
		$stockLocationTable = new Application_Model_Mapper_StockLocation();
		//get shipment type
		$shipmenttypeId = $this->getRequest()->getParam('systemtypeid', -1);
		$this->view->assign('shipmenttype', $shipmenttypeId);
		$shipmentTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::SHIPMENT_TYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_TYPES, $shipmentTypes);
		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);
		//get shipment by id
		$shipment = $shipmentTable->getShipmentById($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT, $shipment);
		//get stock location
		$stockLocation = $stockLocationTable->getAllStockLocation();
		$ArrStockLocation = array();
		$dataAuto = '';
		foreach($stockLocation as $sl) {
			$ArrStockLocation[$sl['stocklocationname']]= $sl['stocklocationid'];
		}
		foreach ($ArrStockLocation as $key=>$value) {
			$dataAuto = $dataAuto."$key|$value#";
		}
		$dataAuto = substr($dataAuto, 0 ,strlen($dataAuto) - 1);
		$this->view->assign(Sss_Ultility_CommonViewParamater::AUTOCOMPLETE, $dataAuto);
		//update hardware when detach
		if($userInformation->username && isset($params['hardwareid']) && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			$resultdetachHardware = Sss_Ultility_InventoryFuction::detachHardware($params, $shipmentId,1,$instanceId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $resultdetachHardware);
		}
		//delete alert
		$deleteAlertId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ALERT_ID, -1);
		if ($userInformation->username && isset($deleteAlertId) && $deleteAlertId != -1) {
			$deleteId   = $alertTable->deleteRow($deleteAlertId,$instanceId);
			$message = isset($deleteId) ? Resources::_('DELETE_ALERT_SUCCESSFULL') : Resources::_('DELETE_ALERT_FAIL');
			$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $message);
		}
		$listAlertShipment = $alertTable->getList(Sss_Ultility_SystemName::SHIPMENTS, $shipmentId);//get alert list for shipment
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT, $listAlertShipment);
		//delete product
		$deleteProductId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_PRODUCT_ID, -1);
		if ($userInformation->username && isset($deleteProductId) && $deleteProductId != -1) {
			$messagedeleteProduct = Sss_Ultility_InventoryFuction::deleteProduct($userInformation,$productTable,$deleteProductId,$instanceId);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $messagedeleteProduct);
		//get product list for shipment
		$listProductShipment = $productTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM, $listProductShipment);
		//delete document
		$deleteDocumentId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_DOCUMENT_ID, -1);
		if ($userInformation->username && isset($deleteDocumentId) && $deleteDocumentId != -1) {
			$messagedeleteDocument = Sss_Ultility_InventoryFuction::deleteDocument($userInformation,$documentTable,$deleteDocumentId,$instanceId);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $messagedeleteDocument);
		$listDocumentShipment = $documentTable->getList($shipmentId);//get document list for shipment
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM, $listDocumentShipment);
		//remove sensor from shipment
		$deleteSensorId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_SENSOR_ID, -1);
		$messageremoveSensor = Sss_Ultility_InventoryFuction::removeSensor($userInformation,$shipmentId,$allocationTable,$deleteSensorId);
		if($messageremoveSensor != "")
			$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $messageremoveSensor);
		//get sensor list for shipment
		$listSensorShipment = $hardwareTable->getListByDestination($shipmentId, Sss_Ultility_SystemName::SHIPMENTS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM, $listSensorShipment);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM_COUNT, count($listSensorShipment));
		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'rma-detail-export?print=1&' . "shipmentid=$shipmentId", Resources::_('PRINT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'rma', Resources::_('BTN_BACK'))
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('RMA'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('RMA_DETAIL'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function rmaDetailExportAction()
	{

		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);

		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_RMA, Sss_Ultility_CommonViewParamater::ALL, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}

		$systemTypeTable = new Shepherd_Model_Mapper_SystemType();
		$shipmentTable   = new Shepherd_Model_Mapper_Shipment();
		$alertTable      = new Shepherd_Model_Mapper_Alert();
		$productTable    = new Shepherd_Model_Mapper_Product();
		$documentTable   = new Shepherd_Model_Mapper_Document();
		$hardwareTable   = new Application_Model_Mapper_Hardware();


		//get shipment type
		$shipmenttypeId = $this->getRequest()->getParam('systemtypeid', -1);

		$this->view->assign('shipmenttype', $shipmenttypeId);

		$shipmentTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::SHIPMENT_TYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_TYPES, $shipmentTypes);

		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);

		//get shipment by id
		$shipment = $shipmentTable->getShipmentById($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT, $shipment);

		//get alert list for shipment
		$listAlertShipment = $alertTable->getList(Sss_Ultility_SystemName::SHIPMENTS, $shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT, $listAlertShipment);

		//get product list for shipment
		$listProductShipment = $productTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM, $listProductShipment);

		//get document list for shipment
		$listDocumentShipment = $documentTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM, $listDocumentShipment);

		//get sensor list for shipment
		$listSensorShipment = $hardwareTable->getListByDestination($shipmentId, Sss_Ultility_SystemName::SHIPMENTS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM, $listSensorShipment);

		$queryString = '?shipmentid=' . $shipmentId;

		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_COMMON, 'rma-detail');
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);

	}
	public function addShipmentAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$systemTypeTable = new Shepherd_Model_Mapper_SystemType();
		$shipmentTable   = new Shepherd_Model_Mapper_Shipment();
		$instanceTable  = new Application_Model_Mapper_Instance();
		$stockLocationTable   = new Application_Model_Mapper_StockLocation();
		//get shipment type
		$shipmenttypeId = $this->getRequest()->getParam('systemtypeid', -1);
		$this->view->assign('shipmenttype', $shipmenttypeId);
		$shipmentTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::SHIPMENT_TYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_TYPES, $shipmentTypes);
		//get monitor id
		$monitorId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::MONITORING_LOCALIZATION, -1);
		$this->view->assign(Sss_Ultility_CommonViewParamater::MONITOR, $monitorId);
		$params = $this->_request->getParams();
		//get shipment type
		$status = $this->getRequest()->getParam('status', -1);
		if (($status == -1 || (int) $status == 0) && isset($params['status']))
			$status = $params['status'];
		$this->view->assign('status', $status);
		$stockLocationDestination = $stockLocationTable->getAllStockLocation();
		if(isset($params['shipmenttype'])) {
			$this->view->assign('shipmenttype', $params['shipmenttype']);
			//get stock locations
			$stockLocationDestination = ($params['shipmenttype'] == Sss_Ultility_Setting::RMA_SHIPMENT) ? $stockLocationTable->getAllStockLocation(null,Sss_Ultility_Setting::INTERNAL_STOCK) : $stockLocationDestination;
		}
		$stockLocationDestination = ($status == Sss_Ultility_Setting::RMA_SHIPMENT) ? $stockLocationTable->getAllStockLocation(null,Sss_Ultility_Setting::INTERNAL_STOCK) : $stockLocationDestination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKDESTINATIONS, $stockLocationDestination);
		//get instance for check when not found
		$instance = $instanceTable->getInstanceByHandle($handle);
		//get stock locations
		$stockLocations = $stockLocationTable->getAllStockLocation();
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATIONS, $stockLocations);
		//get stock location
		$stockLocation  = $stockLocationTable->select($instance->stocklocation);
		$this->view->assign('origin', $stockLocation->stocklocationid);
		$this->view->assign('originname', $stockLocation->stocklocationname);
		$rmaNumber = $shipmentTable->getCountShipmentByType(Sss_Ultility_Setting::RMA_SHIPMENT, Sss_Ultility_Common::getDateTimeNumber(date(DATEFORMAT)));
		$rmaNumber = $rmaNumber + 1;
		$rmaNumber = $rmaNumber < 10 ? '00'.$rmaNumber :($rmaNumber < 100 ? '0'.$rmaNumber:$rmaNumber);
		$rmaNumber = 'OVSRMA-'.date('ymd').'-'.$rmaNumber;
		$this->view->assign(Sss_Ultility_CommonViewParamater::RMA_SHIPMENT_COUNT, $rmaNumber);
		//get stock location
		$stockLocation = $stockLocationTable->getAllStockLocationByShepherd(Sss_Ultility_Setting::INTERNAL_STOCK, $instance->instanceid);
		$ArrStockLocation = array();
		$dataAuto = '';
		foreach($stockLocation as $sl) {
			$ArrStockLocation[$sl['stocklocationname']]= $sl['stocklocationid'];
		}
		foreach ($ArrStockLocation as $key=>$value) {
			$dataAuto = $dataAuto."$key|$value#";
		}
		$dataAuto = substr($dataAuto, 0 ,strlen($dataAuto) - 1);
		$this->view->assign(Sss_Ultility_CommonViewParamater::AUTOCOMPLETE, $dataAuto);
		//get name when page load
		$shipmentName = $this->getValueRequest('shipmentname', $this->getRequest()->getParam('shipmentname', Sss_Ultility_CommonViewParamater::UNDERFINE), 'shipmentSession');
		$this->view->assign('shipmentname', $shipmentName);
		if ($userInformation->username && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			$createBy  = $userInformation->accountid;
			$this->getValueRequest('shipmentname', '', 'shipmentSession');
			$result = Sss_Ultility_InventoryFuction::addShipment($params, $createBy, $status, $shipmenttypeId, $monitorId, $instanceId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::MSG, $result['message']);
			$queryString = '?'.'shipmentid'.'='.$result['shipmentid'].'&'.Sss_Ultility_CommonViewParamater::MONITORING_LOCALIZATION . '=1';
			if($monitorId == 1){
				$this->redirect('', $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'shipment-hardware'
				)) . $queryString);
			} elseif ($status != -1 || $params['shipmenttype'] == Sss_Ultility_Setting::RMA) {
				$this->redirect($result['message'], $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'rma'
				)));
			} else {
				$this->redirect($result['message'], $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'shipments'
				)));
			}
		}
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT'), 'shipment'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_SHIPMENT'), '#')
		);
		if($status != -1) {
			$breadscrumbs = array(
					new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
					new Sss_CommonEntity_BreadScrumb(Resources::_('RMA'), '#'),
					new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_NEW_RMA_SHIPMENT'), '#')
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function shipmentHardwareAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::EDIT, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$hardwareTable   = new Application_Model_Mapper_Hardware();
		$allocationTable = new Shepherd_Model_Mapper_Allocation();
		$shipmentTable   = new Shepherd_Model_Mapper_Shipment();
		$inventoryTable  = new Application_Model_Mapper_Inventory();
		$stocklocationTable  =  new Application_Model_Mapper_StockLocation();
		$stockLocationInstanceTable = new Application_Model_Mapper_StockLocationInstance();
		$instanceTable  = new Application_Model_Mapper_Instance();
		$params     = $this->getRequest()->getParams();
		$isSearch = isset($params['s']) && $params['s'] == 1;
		$status = $this->getRequest()->getParam('status', -1);//get shipment type
		if (($status == -1 || (int) $status == 0) && isset($params['status']))
			$status = $params['status'];
		$this->view->assign('status', $status);
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($params[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $params[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($params[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $params[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($params[Sss_Ultility_CommonViewParamater::PAGE]) ? $params[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramHardwareName   = $isSearch? strcmp($this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('HARDWARE_NAME')) == 0 ? '' : $this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE):'';
		$paramHardwareSerial = $isSearch?strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE):'';
		$paramHardwareVendor = $isSearch?strcmp($this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR')) == 0 ? '' : $this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE):'';
		$monitorId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::MONITORING_LOCALIZATION, -1);//get monitor id
		$this->view->assign(Sss_Ultility_CommonViewParamater::MONITOR, $monitorId);
		//get harware filter
		$filterParam['hardwarename'] = $this->getValueRequest('hardwarename', trim($paramHardwareName), Sss_Ultility_SessionName::SHIPMENT_HARDWARE_SESSION);
		$filterParam['serial_number'] = $this->getValueRequest('serial_number', trim($paramHardwareSerial), Sss_Ultility_SessionName::SHIPMENT_HARDWARE_SESSION);
		$filterParam['vendor']        = $this->getValueRequest('vendor', trim($paramHardwareVendor), Sss_Ultility_SessionName::SHIPMENT_HARDWARE_SESSION);

		$defaultNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::SHEPHERD_SYSTEM . $this->getCurrentHandle());
		$filterParam['stocklocation'] = $defaultNamespace->stocklocationId;
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);//get shipmentid
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);
		$shipmentdetail = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL, -1);
		if (($shipmentdetail == -1 || (int) $shipmentdetail == 0) && isset($params[Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL]))
			$shipmentdetail = $params[Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL];
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL, $shipmentdetail);
		$instance = $instanceTable->getInstanceByHandle($handle);
		$stockLocations = $instance ? $stockLocationInstanceTable->getStockLocationByInstance($instance->instanceid) : null;
		$stockLocationIds = '';
		if($stockLocations != null && count($stockLocations) > 0){
			foreach($stockLocations as $s){
				$stockLocationIds = ($stockLocationIds == '') ? $s['stocklocation'] : $stockLocationIds.','.$s['stocklocation'];
			}
		}
		$filterParam['stocklocation'] = ($stockLocationIds != '') ? $stockLocationIds : $filterParam['stocklocation'];
		$shipment     = $shipmentTable->getShipmentById($shipmentId);//get shipment
		$shipmentName = $shipment->shipmentname;
		$shipmentType = $shipment->shipmenttype;
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_NAME, $shipmentName);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_TYPE, $shipmentType);
		if ($params && $userInformation->username && !isset($params["btnSearch"])  && isset($params["ids"])) {
			//assign hardware to item
			$arrAssignHardwareId = explode('_', $params[Sss_Ultility_CommonViewParamater::IDS]);
			if (false != $arrAssignHardwareId) {
				try {
					Sss_Ultility_InventoryFuction::assignHardwareToItem($arrAssignHardwareId,$shipment,$shipmentId,$allocationTable,$hardwareTable,$inventoryTable,$params,$stocklocationTable, $instanceId);
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('SENSOR_ATTACH_TO_SHIPMENT_SUCCESSFULL'));
				} catch(exception $e) {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('SENSOR_ATTACH_TO_SHIPMENT_FAIL'));
				}
			}
		}
		$result = Sss_Ultility_InventoryFuction::getQuery($status,$shipmentId,$shipmentdetail,$monitorId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $result[0]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $result[1]);
		$listSensorShipment = $hardwareTable->getListByDestination($shipmentId, Sss_Ultility_SystemName::SHIPMENTS );//get sensor list for shipment
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM, $listSensorShipment);
		$allocation = $allocationTable->getById($shipmentId, Sss_Ultility_SystemName::SHIPMENTS);//get allocation
		$this->view->assign(Sss_Ultility_CommonViewParamater::ALLOCATION, $allocation);
		$list       = $hardwareTable->getListForItem($this->view->limit, 0, $filterParam);
		$row        = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign('isSearch', $isSearch);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$actionbuttons = array(new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH')));//action button
		$actionbuttons = (count($row) <= 0) ? null : $actionbuttons;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ATTACH_SENSORS'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function documentAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());


		$documentTable = new Shepherd_Model_Mapper_Document();

		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);

		//get shipment type
		$status = $this->getRequest()->getParam('status', -1);
		if (($status == -1 || (int) $status == 0) && isset($params['status']))
			$status = $params['status'];
		$this->view->assign('status', $status);

		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		if ($userInformation->username) {
			//delete document
			$deleteDocumentId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_DOCUMENT_ID, -1);
			if (isset($deleteDocumentId) && $deleteDocumentId != -1) {
				$document = $documentTable->getDocumentById($deleteDocumentId);
				if ($document->path) {
					if (file_exists(getcwd() . $document->path))
						unlink(getcwd() . $document->path);
				}
				$deleteId      = $documentTable->deleteRow($deleteDocumentId);
				if (isset($deleteId)) {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_DOCUMENT_SUCCESSFULL'));
				} else {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_DOCUMENT_FAIL'));
				}
			}
		}

		//get document list for shipment
		$listDocumentShipment = $documentTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM, $listDocumentShipment);

		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_QUERY_STRING, '?' . 'shipmentid' . "=" . $shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_CONTROLLER_NAME, Sss_Ultility_CommonViewParamater::INVENTORY);
		if($status != -1) {
			$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_QUERY_STRING, '?' . 'shipmentid' . "=" . $shipmentId. '&' . 'status' . "=" . Sss_Ultility_Setting::RMA);
		}

		if($status != -1){
			//action button
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADDOTHER, "add-document", Resources::_('ADD_DOCUMENT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'rma', Resources::_('BTN_BACK'))
			);
		} else{
			//action button
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADDOTHER, "add-document", Resources::_('ADD_DOCUMENT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'rma', Resources::_('BTN_BACK'))
			);
		}

		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1)
		{
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'rma', Resources::_('BTN_BACK'))
			);
			if($status != -1){
				$actionbuttons = array(
						new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'rma', Resources::_('BTN_BACK'))
				);
			}
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);

		$title = Resources::_('SHIPMENT');
		if($status != -1){
			$title = Resources::_('RMA');
		}
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb($title, '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('DOCUMENT'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function addDocumentAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		$documentTable = new Shepherd_Model_Mapper_Document();
		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);
		//get shipment type
		$status = $this->getRequest()->getParam('status', -1);
		if (($status == -1 || (int) $status == 0) && isset($params['status']))
			$status = $params['status'];
		$this->view->assign('status', $status);
		$documentId = $this->getRequest()->getParam('documentid', -1);
		if (($documentId == -1 || (int) $documentId == 0) && isset($params['documentid']))
			$documentId = $params['documentid'];
		$this->view->assign('documentid', $documentId);
		$shipmentdetail = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL, -1);
		if (($shipmentdetail == -1 || (int) $shipmentdetail == 0) && isset($params[Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL]))
			$shipmentdetail = $params[Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL];
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL, $shipmentdetail);
		$strAction   = 'document';
		$queryString = '?' . 'shipmentid' . "=" . $shipmentId;
		$queryString = ($status != -1) ? '?' . 'shipmentid' . "=" . $shipmentId . '&' . 'status' . "=" . Sss_Ultility_Setting::RMA : $queryString;
		if ($shipmentdetail != -1) {
			$strAction   = 'rma-detail';
			$queryString = '?' . 'shipmentid' . "=" . $shipmentId . '&' . Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL . '=1';
			$strAction = ($status != -1) ? 'rma-detail' : $strAction;
			$queryString = ($status != -1) ? '?' . 'shipmentid' . "=" . $shipmentId . '&' . Sss_Ultility_CommonViewParamater::SHIPMENT_DETAIL . '=1&' . 'status' . "=" . Sss_Ultility_Setting::RMA : $queryString;
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);
		//get document edit
		$document = $documentTable->getDocumentById($documentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $document);
		$actionName = '';
		if ($documentId != -1) {
			//check permission
			if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::EDIT, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
				$this->_redirect("/$handle/user/login");
			}
			$actionName = Resources::_('EDIT_DOCUMENT');
		} else {
			//check permission
			if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
				$this->_redirect("/$handle/user/login");
			}
			$actionName = Resources::_('ADD_DOCUMENT');
		}
		if ($userInformation->username && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			//upload document
			$fullPath = null;
			$fileName = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::NAME];
			if ($fileName) {
				$filePath = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::TMP_NAME];
				$newPath  = Sss_Ultility_CommonViewParamater::FILE_PATH_DOCUMENT . $fileName;
				move_uploaded_file($filePath, $newPath);
				$fullPath     = '/' . Sss_Ultility_CommonViewParamater::FILE_PATH_DOCUMENT . $fileName;
			}
			$createBy = $userInformation->accountid;
			// Process add/edit new document
			$result = Sss_Ultility_InventoryFuction::addEditDocument($params, $fileName, $fullPath, $createBy, $document, $shipmentId, $documentId, $instanceId);
			$this->redirect($result, $this->view->url(array(
					Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
					Sss_Ultility_CommonViewParamater::ACTION => $strAction
			)) . $queryString);
		}
		$title = ($status != -1) ? Resources::_('RMA') : Resources::_('SHIPMENT');
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb($title, '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('DOCUMENT'), '#'),
				new Sss_CommonEntity_BreadScrumb($actionName, '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function shipmentHistoryAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$this->getValueRequest('shipmentname', '', Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::VISIBLE, 'feature', 'action' ,$this->listRole(), true) == 1 ){
			$shipmentTable = new Shepherd_Model_Mapper_Shipment();
			$alertTable    = new Shepherd_Model_Mapper_Alert();
			$productTable  = new Shepherd_Model_Mapper_Product();
			$documentTable = new Shepherd_Model_Mapper_Document();
			$hardwareTable = new Application_Model_Mapper_Hardware();
			$stockLocationTable = new Application_Model_Mapper_StockLocation();
			//get order, page, limit param
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERFIELD, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERFIELD, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERTYPE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERTYPE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam[Sss_Ultility_CommonViewParamater::PAGE]       = $this->getValueRequest(Sss_Ultility_CommonViewParamater::PAGE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::PAGE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			//test param filter: omit title text in field
			$paramOriginal        = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'origin', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$paramDestination     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'destination', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$paramFromDate        = $this->getRequest()->getParam('date_from', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$paramToDate          = $this->getRequest()->getParam('date_to', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$paramInternalRef     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$paramSupplierRef     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$paramReferenceNumber = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', Sss_Ultility_CommonViewParamater::UNDERFINE);
			//get shipment filter
			$filterParam['origin']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'origin', trim($paramOriginal), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam['destination']      = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'destination', trim($paramDestination), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam['date_from']        = $this->getValueRequest('date_from', $paramFromDate, Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam['date_to']          = $this->getValueRequest('date_to', $paramToDate, Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam['internal_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', trim($paramInternalRef), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam['supplier_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', $paramSupplierRef, Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$filterParam['reference_number'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', trim($paramReferenceNumber), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_HISTORY_SESSION);
			$params     = $this->getRequest()->getPost();
			if ($userInformation->username) {
				$message = Sss_Ultility_InventoryFuction::updateHardwareDetach($params,$hardwareTable);
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $message);
			}
			$filterParam['shipment_history'] = 1;
			$list                 = $shipmentTable->getList($limit, 0, $filterParam);//get shipment list
			$row                  = $list->list;
			$result = Sss_Ultility_InventoryFuction::getInformationShipmentHistory($row,$alertTable,$productTable,$documentTable,$hardwareTable);
			$listAlertShipment    = $result[0];
			$listProductShipment  = $result[1];
			$listDocumentShipment = $result[2];
			$listSensorShipment   = $result[3];
			$stockLocation = $stockLocationTable->getAllStockLocation();//get stock location
			$ArrStockLocation = array();
			$dataAuto = '';
			foreach($stockLocation as $sl){
				$ArrStockLocation[$sl['stocklocationname']]= $sl['stocklocationid'];
			}
			foreach ($ArrStockLocation as $key=>$value) {
				$dataAuto = $dataAuto."$key|$value#";
			}
			$dataAuto = substr($dataAuto, 0 ,strlen($dataAuto) - 1);
			$this->view->assign(Sss_Ultility_CommonViewParamater::AUTOCOMPLETE, $dataAuto);
			$countSensor = 0;
			foreach($listSensorShipment as $ls){
				foreach($ls as $s){
					$countSensor = $countSensor + 1;
				}
			}
			$hardwareByShipment = $hardwareTable->getHardwareByDestinationGraph('', Sss_Ultility_SystemName::SHIPMENTS, 0);
			$chartsByShipment = Sss_Ultility_InventoryFuction::getChartsByShipment($hardwareByShipment,$hardwareTable);
			$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE_BY_SHIPMENT, $chartsByShipment);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM_COUNT, $countSensor);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT, $listAlertShipment);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM, $listProductShipment);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM, $listDocumentShipment);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM, $listSensorShipment);
			$pagination = $list->pagination;
			$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
			$this->view->assign(Sss_Ultility_CommonViewParamater::LIMIT, $limit);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
			$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'shipment-history-export?shipmenthistory=1&export=1', Resources::_('EXPORT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'shipment-history-export?shipmenthistory=1&print=1', Resources::_('PRINT')),
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
			if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 )
			{
				$actionbuttons = array(
						new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'shipment-history-export?export=1', Resources::_('EXPORT')),
						new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'shipment-history-export?print=1', Resources::_('PRINT')),
						new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
				);
			}
			$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
			$breadscrumbs = array(
					new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
					new Sss_CommonEntity_BreadScrumb(Resources::_('RMA'), 'rma'),
					new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT_HISTORY'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
	}
	public function editShipmentAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::EDIT, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
			$this->_redirect("/$handle/user/login");
		}
		$permissionTable = new Shepherd_Model_Mapper_Permission();

		$instanceTable   = new Application_Model_Mapper_Instance();
		$systemTypeTable = new Shepherd_Model_Mapper_SystemType();
		$shipmentTable   = new Shepherd_Model_Mapper_Shipment();
		$stockLocationTable   = new Application_Model_Mapper_StockLocation();
		//get shipment type
		$shipmenttypeId = $this->getRequest()->getParam('systemtypeid', -1);
		$this->view->assign('shipmenttype', $shipmenttypeId);
		$shipmentTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::SHIPMENT_TYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_TYPES, $shipmentTypes);
		$params = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);
		//get shipment type
		$status = $this->getRequest()->getParam('status', -1);
		if (($status == -1 || (int) $status == 0) && isset($params['status']))
			$status = $params['status'];
		$this->view->assign('status', $status);
		//get shipment by id
		$shipment = $shipmentTable->getShipmentById($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT, $shipment);
		$stockLocationDestination = $stockLocationTable->getAllStockLocation();
		if(isset($params['shipmenttype'])) {
			$this->view->assign('shipmenttype', $params['shipmenttype']);
			//get stock locations
			if($params['shipmenttype'] == Sss_Ultility_Setting::RMA_SHIPMENT) {
				$stockLocationDestination = $stockLocationTable->getAllStockLocation(null,Sss_Ultility_Setting::INTERNAL_STOCK);
			}
		}
		if($shipment->shipmenttype == Sss_Ultility_Setting::RMA_SHIPMENT) {
			$stockLocationDestination = $stockLocationTable->getAllStockLocation(null,Sss_Ultility_Setting::INTERNAL_STOCK);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKDESTINATIONS, $stockLocationDestination);
		//get stock locations
		$stockLocations = $stockLocationTable->getAllStockLocation();
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATIONS, $stockLocations);
		//get controller and action
		$strController  = Sss_Ultility_CommonViewParamater::INVENTORY;
		$strAction      = 'shipment';
		$inventoryParam = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::INVENTORY, -1);
		if (($inventoryParam == -1) && isset($params[Sss_Ultility_CommonViewParamater::INVENTORY]))
			$inventoryParam = $params[Sss_Ultility_CommonViewParamater::INVENTORY];
		$this->view->assign(Sss_Ultility_CommonViewParamater::INVENTORY, $inventoryParam);
		if ($inventoryParam != -1 && $inventoryParam == 0) {
			$strController = Sss_Ultility_CommonViewParamater::MONITORING_LOCALIZATION;
			$strAction     = 'dynamicmonitoring';
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			//check permission
			if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_DYNAMIC_MONITORING, Sss_Ultility_CommonViewParamater::ALL, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
				$this->_redirect("/$handle/user/login");
			}
		}
		$strAction = ($status != -1) ? "rma" : $strAction;
		$this->view->assign(Sss_Ultility_CommonViewParamater::CONTROLLER, $strController);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);
		//get instance for check when not found
		$instance = $instanceTable->getInstanceByHandle($handle);
		//get stock location
		$stockLocation = $stockLocationTable->getAllStockLocationByShepherd(Sss_Ultility_Setting::INTERNAL_STOCK, $instance->instanceid);
		$ArrStockLocation = array();
		$dataAuto = '';
		foreach($stockLocation as $sl) {
			$ArrStockLocation[$sl['stocklocationname']]= $sl['stocklocationid'];
		}
		foreach ($ArrStockLocation as $key=>$value) {
			$dataAuto = $dataAuto."$key|$value#";
		}
		$dataAuto = substr($dataAuto, 0 ,strlen($dataAuto) - 1);
		$this->view->assign(Sss_Ultility_CommonViewParamater::AUTOCOMPLETE, $dataAuto);
		$createBy = $userInformation->accountid;
		//edit shipment
		if ($userInformation->username && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE]) && $shipmentId != -1) {
			$message = Sss_Ultility_InventoryFuction::editShipment($params, $createBy, $shipmentId, $instanceId);
			$this->redirect($message, $this->view->url(array(
					Sss_Ultility_CommonViewParamater::CONTROLLER => $strController,
					Sss_Ultility_CommonViewParamater::ACTION => $strAction
			)));
		}
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('RMA'), 'rma'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('EDIT_SHIPMENT'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function shipmentHistoryExportAction()
	{
		$shipmentTable = new Shepherd_Model_Mapper_Shipment();
		$params = $this->_request->getParams();

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramOriginal        = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'origin', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramDestination     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'destination', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramFromDate        = $this->getRequest()->getParam('date_from', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramToDate          = $this->getRequest()->getParam('date_to', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramInternalRef     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramSupplierRef     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramReferenceNumber = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', Sss_Ultility_CommonViewParamater::UNDERFINE);



		//get shipment filter
		$filterParam['origin']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'origin', $paramOriginal, 'shipmentSession');
		$filterParam['destination']      = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'destination', $paramDestination, 'shipmentSession');
		$filterParam['date_from']        = $this->getValueRequest('date_from', $paramFromDate, 'shipmentSession');
		$filterParam['date_to']          = $this->getValueRequest('date_to', $paramToDate, 'shipmentSession');
		$filterParam['internal_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'internal_ref', $paramInternalRef, 'shipmentSession');
		$filterParam['supplier_ref']     = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'supplier_ref', $paramSupplierRef, 'shipmentSession');
		$filterParam['reference_number'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'reference_number', $paramReferenceNumber, 'shipmentSession');



		//get shipment history
		$filterParam['shipment_history'] = 1;
		$columnNames = array(
				Resources::_('ID'),
				Resources::_('NAME'),
				Resources::_('SHIPMENT_ORGIN_LIST'),
				Resources::_('SHIPMENT_DESTINATION_LIST'),
				Resources::_('DATE'),
				Resources::_('SHIPMENT_END_DATE')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_HISTORY, $shipmentHistoryId);
		//get shipment list
		$list = $shipmentTable->getList(-1, 0, $filterParam);
		$rowAll  = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));


		$arrData = array();
		$index = 0;
		if($shipmentHistoryId != -1){
			foreach((array)$rowAll as $row)
			{
				$count++;
				$arrData[$index][] = $count;
				$arrData[$index][] = $row['shipmentname'];
				$arrData[$index][] = $row['origin'];
				$arrData[$index][] = $row['destination'];
				$arrData[$index][] = Sss_Ultility_Common::getDateTime(DATETIMEFORMAT, $row['ship_date']);
				$arrData[$index][] = Sss_Ultility_Common::getDateTime(DATETIMEFORMAT, $row['end_date']);
				$index++;
			}
		}else{
			foreach((array)$rowAll as $row)
			{
				$count++;
				$arrData[$index][] = $count;
				$arrData[$index][] = $row['shipmentname'];
				$arrData[$index][] = $row['origin'];
				$arrData[$index][] = $row['destination'];
				$arrData[$index][] = Sss_Ultility_Common::getDateTime(DATETIMEFORMAT, $row['ship_date']);
				$index++;
			}
		}

		if(isset($_GET['export']))
			$this->exportDataToExcel($columnNames, $arrData, Resources::_('SHIPMENT_HISTORY'));

	}
	public function shipmentHistoryDetailAction()
	{
		$systemTypeTable = new Shepherd_Model_Mapper_SystemType();
		$shipmentTable   = new Shepherd_Model_Mapper_Shipment();
		$alertTable      = new Shepherd_Model_Mapper_Alert();
		$productTable    = new Shepherd_Model_Mapper_Product();
		$documentTable = new Shepherd_Model_Mapper_Document();
		$hardwareTable   = new Application_Model_Mapper_Hardware();

		//get shipment type
		$shipmenttypeId = $this->getRequest()->getParam('systemtypeid', -1);
		$this->view->assign('shipmenttype', $shipmenttypeId);
		$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
		$instanceId = $defaultOvisNamespace->dbShepherd;

		$shipmentTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::SHIPMENT_TYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_TYPES, $shipmentTypes);

		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);

		//get shipment by id
		$shipment = $shipmentTable->getShipmentById($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT, $shipment);

		//list alert for shipment detail
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());

		//get alert list for shipment
		$listAlertShipment = $alertTable->getList(Sss_Ultility_SystemName::SHIPMENTS, $shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT, $listAlertShipment);

		//get product list for shipment
		$listProductShipment = $productTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM, $listProductShipment);

		//get document list for shipment
		$listDocumentShipment = $documentTable->getList($shipmentId,$instanceId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM, $listDocumentShipment);

		//get sensor list for shipment
		$listSensorShipment = $hardwareTable->getListByDestination($shipmentId, Sss_Ultility_SystemName::SHIPMENTS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM, $listSensorShipment);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM_COUNT, count($listSensorShipment));

		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'shipment-detail-export?print=1&' . "shipmentid=$shipmentId", Resources::_('PRINT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'shipment-history', Resources::_('BTN_BACK'))
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);

		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT_HISTORY'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT_DETAIL'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function alertAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());


		$alertTable = new Shepherd_Model_Mapper_Alert();

		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);

		$this->getValueRequest('alertname', '', Sss_Ultility_SessionName::ADD_NEW_ALERT_SESSION);
		$this->getValueRequest('value', '', Sss_Ultility_SessionName::ADD_NEW_ALERT_SESSION);
		$this->getValueRequest('email', '', Sss_Ultility_SessionName::ADD_NEW_ALERT_SESSION);
		$this->getValueRequest('note', '', Sss_Ultility_SessionName::ADD_NEW_ALERT_SESSION);

		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		if ($userInformation->username) {
			//delete alert
			$deleteAlertId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ALERT_ID, -1);
			if (isset($deleteAlertId) && $deleteAlertId != -1) {
				$deleteId   = $alertTable->deleteRow($deleteAlertId);
				if (isset($deleteId)) {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_ALERT_SUCCESSFULL'));
				} else {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_ALERT_FAIL'));
				}
			}
		}

		//get alert list for shipment
		$listAlertShipment = $alertTable->getList(Sss_Ultility_SystemName::SHIPMENTS, $shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT, $listAlertShipment);

		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_QUERY_STRING, '?' . 'shipmentid' . "=" . $shipmentId . '&' . Sss_Ultility_CommonViewParamater::INVENTORY . '=1');
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_CONTROLLER_NAME, Sss_Ultility_CommonViewParamater::MONITORING_LOCALIZATION);

		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADDOTHER, "add-alert", Resources::_('ADD_ALERT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'shipment', Resources::_('BTN_BACK'))
		);
		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ){
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'shipment', Resources::_('BTN_BACK'))
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);

		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ALERTS'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function productAction()
	{
		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());


		$productTable = new Shepherd_Model_Mapper_Product();

		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);

		$userInformation = new Zend_Session_Namespace('shepherdaccount' . $this->getCurrentHandle());
		if ($userInformation->username) {
			//delete product
			$deleteProductId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_PRODUCT_ID, -1);
			if (isset($deleteProductId) && $deleteProductId != -1) {
				$deleteId     = $productTable->deleteRow((int) $deleteProductId);
				if (isset($deleteId)) {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_PRODUCT_SUCCESSFULL'));
				} else {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_PRODUCT_FAIL'));
				}
			}
		}
		//get product list for shipment
		$listProductShipment = $productTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM, $listProductShipment);
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_QUERY_STRING, '?' . 'shipmentid' . "=" . $shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_CONTROLLER_NAME, Sss_Ultility_CommonViewParamater::INVENTORY);
		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADDOTHER, "add-product", Resources::_('ADD_DOCUMENT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'shipment', Resources::_('BTN_BACK'))
		);

		//check permission
		if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_SHIPMENT, Sss_Ultility_CommonViewParamater::ADD, 'feature', 'action' ,$this->listRole(), true) != 1 ){
			$actionbuttons = array(
					new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'shipment', Resources::_('BTN_BACK'))
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);

		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('SHIPMENT'), '#'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('PRODUCT'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function shipmentDetailExportAction()
	{
		$systemTypeTable = new Shepherd_Model_Mapper_SystemType();
		$shipmentTable   = new Shepherd_Model_Mapper_Shipment();
		$alertTable      = new Shepherd_Model_Mapper_Alert();
		$productTable    = new Shepherd_Model_Mapper_Product();
		$documentTable   = new Shepherd_Model_Mapper_Document();
		$hardwareTable   = new Application_Model_Mapper_Hardware();


		//get shipment type
		$shipmenttypeId = $this->getRequest()->getParam('systemtypeid', -1);
		$this->view->assign('shipmenttype', $shipmenttypeId);

		$shipmentTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::SHIPMENT_TYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT_TYPES, $shipmentTypes);

		//get shipmentid
		$params     = $this->getRequest()->getPost();
		$shipmentId = $this->getRequest()->getParam('shipmentid', -1);
		if (($shipmentId == -1 || (int) $shipmentId == 0) && isset($params['shipmentid']))
			$shipmentId = $params['shipmentid'];
		$this->view->assign('shipmentid', $shipmentId);

		//get shipment by id
		$shipment = $shipmentTable->getShipmentById($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT, $shipment);

		//get alert list for shipment
		$listAlertShipment = $alertTable->getList(Sss_Ultility_SystemName::SHIPMENTS, $shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_ALERT_SHIPMENT, $listAlertShipment);

		//get product list for shipment
		$listProductShipment = $productTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_PRODUCT_ITEM, $listProductShipment);

		//get document list for shipment
		$listDocumentShipment = $documentTable->getList($shipmentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DOCUMENT_ITEM, $listDocumentShipment);

		//get sensor list for shipment
		$listSensorShipment = $hardwareTable->getListByDestination($shipmentId, Sss_Ultility_SystemName::SHIPMENTS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_SENSOR_ITEM, $listSensorShipment);

		$queryString = '?shipmentid=' . $shipmentId;

		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_COMMON, 'shipment-detail');
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
	}
	public function myHardwareAction()
	{

		$vendorTable = new Application_Model_Mapper_Vendor();
		$instanceTable  = new Application_Model_Mapper_Instance();
		$get  = $this->getRequest()->getParams();

		$isSearch = isset($get['s']) && $get['s'] == 1;

		//get order, page, limit param
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;

		//test param filter: omit title text in field
		$paramName = $isSearch ? strcmp($this->getRequest()->getParam('name', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('NAME')) == 0 ? '' : $this->getRequest()->getParam('name', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		$paramType = $isSearch ? strcmp($this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('TYPE')) == 0 ? '' : $this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		$paramVendor = $isSearch ? strcmp($this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALL')) == 0 ? '' : $this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		$paramSerial = $isSearch ? strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		$paramLocation = $isSearch ? strcmp($this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('LOCATION')) == 0 ? '' : $this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		$paramAllocation = $isSearch ? strcmp($this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALLOCATION')) == 0 ? '' : $this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		//get harware filter
		$filterParam['hardwarename'] = $this->getValueRequest('name', trim($paramName), Sss_Ultility_SessionName::HARDWARE_SESSION);

		$filterParam['typename'] = $this->getValueRequest('typename', trim($paramType), Sss_Ultility_SessionName::HARDWARE_SESSION);

		$filterParam['vendor'] = $this->getValueRequest('vendor', trim($paramVendor), Sss_Ultility_SessionName::HARDWARE_SESSION);

		$filterParam['serial_number'] = $this->getValueRequest('serial_number', trim($paramSerial), Sss_Ultility_SessionName::HARDWARE_SESSION);

		$filterParam['stocklocationname'] = $this->getValueRequest('stocklocationname', trim($paramLocation), Sss_Ultility_SessionName::HARDWARE_SESSION);

		$filterParam['allocation'] = $this->getValueRequest('allocation', trim($paramAllocation), Sss_Ultility_SessionName::HARDWARE_SESSION);



		//get vendor
		$vendor = $vendorTable->getList();
		$this->view->assign(Sss_Ultility_CommonViewParamater::VENDOR, $vendor);



		//get handle name
		$handle   = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);

		//get instance
		$instance = $instanceTable->getInstanceByHandle($handle);

		//get hardware list
		$list       = Sss_Ultility_Common::getListMyHardware($this->view->limit, 0, $filterParam,$instance->instanceid);
		$row        = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$orderQueryString = '';
		if ($isSearch) {
			$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE] . '&s=1';
		} else {
			$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		}
		$queryString = '';
		if ($isSearch) {
			$queryString .= '&s=1';
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD])){
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD];
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE])){
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE];
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, "javascript:hardwareExport('".$instance->instanceid."','".$this->getRequest()->getParam('hardwarename')."','".$this->getRequest()->getParam('typename')."','".$this->getRequest()->getParam('vendor')."','".$this->getRequest()->getParam('serial_number')."','".$this->getRequest()->getParam('stocklocationname')."','".$this->getRequest()->getParam('allocation')."','".$isSearch."','".$get[Sss_Ultility_CommonViewParamater::ORDERFIELD]."','".$get[Sss_Ultility_CommonViewParamater::ORDERTYPE]."','".$get[Sss_Ultility_CommonViewParamater::PAGE]."');void(0);", Resources::_('EXPORT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, "javascript:hardwarePrint('".$instance->instanceid."','".$this->getRequest()->getParam('hardwarename')."','".$this->getRequest()->getParam('typename')."','".$this->getRequest()->getParam('vendor')."','".$this->getRequest()->getParam('serial_number')."','".$this->getRequest()->getParam('stocklocationname')."','".$this->getRequest()->getParam('allocation')."','".$isSearch."','".$get[Sss_Ultility_CommonViewParamater::ORDERFIELD]."','".$get[Sss_Ultility_CommonViewParamater::ORDERTYPE]."','".$get[Sss_Ultility_CommonViewParamater::PAGE]."');void(0);", Resources::_('PRINT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
		);
		//}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('MY_HARDWARE'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
	public function hardwareDetailAction()
	{
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$systemTypeTable       = new Application_Model_Mapper_SystemType();
		$vendorTable     = new Application_Model_Mapper_Vendor();

		$documentTable = new Application_Model_Mapper_Document();
		$linkTable       = new Application_Model_Mapper_Link();
		$historyTable = new Application_Model_Mapper_History();
		//get hardwareid
		$params = $this->getRequest()->getPost();
		$hardwareId = $this->getRequest()->getParam('hardwareid', -1);
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);

		//get hardware type
		$hardwareTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HARDWARETYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_TYPES, $hardwareTypes);

		//get hardware status
		$hardwareStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::STATUS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_STATUS, $hardwareStatus);

		//get vendor
		$vendor = $vendorTable->getList();
		$this->view->assign(Sss_Ultility_CommonViewParamater::VENDOR, $vendor);

		//get document list
		$documents = $documentTable->getList($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::DOCUMENT, $documents);
			
		//get ticket list
		$tickets = $linkTable->getList($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LINK, $tickets);

		//get hardware list
		$hardware = $hardwareTable->getHardwareById($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE, $hardware);

		//get history list
		$history = $historyTable->getList($hardwareId, Sss_Ultility_Setting::HISTORY_TYPE_HARDWARE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORY, $history);

		//get history type
		$historyTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HISTORYTYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORYTPYE, $historyTypes);

		//set action and query string

		$queryString = '?' . 'hardwareid' . "=" . $hardwareId;
		$filePath = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FILEPATH, -1);
		if($filePath != -1) {
			Sss_Ultility_Common::downloadFile($filePath);
			$this->redirect($this->view->url(array(
					Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
					Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
			)).$queryString);
		}
		$actionName = 'my-hardware';
		$hardwareTitle = Resources::_('MY_HARDWARE');
		$harhwareDetailTitle = Resources::_('HARDWARE_DETAIL');

		//action button
		$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, "javascript:printHardwareDetail($hardwareId)", Resources::_('PRINT')),
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, $actionName, Resources::_('BTN_BACK'))
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb($hardwareTitle, $actionName),
				new Sss_CommonEntity_BreadScrumb($harhwareDetailTitle, '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}
}
